package com.woniu.humanresource.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.humanresource.entity.Accets;
import com.woniu.humanresource.service.AccetsService;
import com.woniu.humanresource.dao.AccetsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author xiang
* @description 针对表【accets】的数据库操作Service实现
* @createDate 2022-07-06 12:19:35
*/
@Service
public class AccetsServiceImpl extends ServiceImpl<AccetsMapper, Accets> implements AccetsService{
    @Autowired
    AccetsMapper accetsMapper;

    //分页查询
    @Override
    public Page<Accets> getAllAccets(int pageIndex,int pageSize,Accets accets) {
        //分页
        Page<Accets> page=new Page<>(pageIndex,pageSize);//页码，页大小

        //查询条件
        QueryWrapper<Accets> queryWrapper=new QueryWrapper<>();
        //组装条件，参数:(满足条件就加这个条件，数据库字段，具体条件)
        queryWrapper.eq(accets.getStatus()!=null, "accets_status",accets.getStatus())//status状态
                    .eq(StringUtils.isNotEmpty(accets.getDepartment()), "accets_department", accets.getDepartment())//department部门
                    .like(StringUtils.isNotEmpty(accets.getName()), "accets_name", accets.getName());//name资产名

        accetsMapper.selectPage(page, queryWrapper);//调mybatisplus的方法去查询，如果没有条件的话查询所有分页

        return page;
    }

    //单个删除
    @Override
    public void removeAccetsById(int accetsId) {
        //创建删除的对象。设置id，根据id修改。设置status，修改status为设置的值。
        Accets newAccets=new Accets();
        newAccets.setId(accetsId);
        newAccets.setStatus(0);

        accetsMapper.updateById(newAccets);//调mybatisplus的方法去修改状态
    }

    //批量删除
    @Override
    public void removeMultipleAccetsById(List<Accets> accets) {
        //创建删除的对象。设置id，根据id修改。设置status，修改status为设置的值。
        Accets newAccets=new Accets();
        newAccets.setStatus(0);

        for(int i=0;i<accets.size();i++){
            newAccets.setId(accets.get(i).getId());
            accetsMapper.updateById(newAccets);//调mybatisplus的方法去修改状态
        }
    }
}




